package lab4p3;

/**
 * <p>Title: DatePanel</p>
 * <p>Description: CS 235 Lab #4</p>
 *         A simple Java graphical user interface component
 *         that keeps track of a single date.
 * @author Anthony Varghese
 * @date   August 8th 2013
 * @team   
 */

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.BevelBorder;





public class DatePanel extends JPanel implements ActionListener {
	/**
	 * Data members
	 */
	private static final long serialVersionUID = 1L;

	private JLabel     description;
	private JComboBox<Integer> hours;
	private JLabel     colon;
	private final String COLON_STRING = ":";
	private JComboBox<Integer> minutes;
	private JLabel     ampm;
	private String AMPM_STRING = "AM";

	private JLabel on;
	private final String ON_STRING = "on";
	private JTextField day;
	private JTextField month;
	private JTextField year;
	private JLabel     yearprefix;
	private final String YEAR_PREFIX_STRING = "20";
	
	private int[] datedata = new int[6]; // 0 == minute, 1 == hour, 2 == day, 3 == month, 4 == year
	
	/**
	 * Constructor for DatePanel class
	 * 
	 * @param descriptionString
	 */
	public DatePanel(String descriptionString) {
		super();

		description = new JLabel( descriptionString );						add( description );
		hours = new JComboBox<Integer>(new NumberComboBoxModel(0,23));		add( hours );
		colon = new JLabel( COLON_STRING );									add( colon );
		minutes = new JComboBox<Integer>(new NumberComboBoxModel(0,59));	add( minutes );
		ampm = new JLabel( AMPM_STRING );					add( ampm );
		on = new JLabel( ON_STRING );						add( on );
		month = new JTextField("", 2);						add( month );
		day = new JTextField("", 2);						add( day );
		yearprefix = new JLabel( YEAR_PREFIX_STRING );		add( yearprefix );
		year = new JTextField("", 2);						add( year );
		year.addActionListener( this );
		
		setBorder( BorderFactory.createBevelBorder(BevelBorder.LOWERED ) );
	}


	/**
	 * actionPerformed
	 * @param e - ActionEvent
	 */
	public void actionPerformed(ActionEvent e) {
		Object source = e.getSource();
		if (source == month)
			System.out.println("Month: " + month.getText() );
		if (source == year)
			System.out.println("Year: " + year.getText() );
	}
	
	public int[] getDate(){
		datedata[0] = Integer.parseInt( minutes.getSelectedItem().toString() );
		datedata[1] = Integer.parseInt( hours.getSelectedItem().toString() );
		datedata[2] = Integer.parseInt( day.getText() );
		datedata[3] = Integer.parseInt( month.getText() );
		datedata[4] = Integer.parseInt( year.getText() );
		return datedata;
	}
}
